<template>
	<view>
		<comlist 
			title="创建生活方式问卷" 
			@comSearch="comSearch"  
			:listtitle="listtitle" 
			:listLabel="listLabel" 
			:list="list"  
			:options="options" 
			:addpageUrl="'/pages/quickly/assessment/investigation'" 
			@bindClick="bindClick" 
			@jump="jump"
			:nullData="nullData"
		>
		</comlist>
		<u-modal v-model="showModal" :show-cancel-button="true" @confirm="Modalconfirm" :content="showContent"></u-modal>
	</view>
</template>

<script>
import comlist from '@/components/comlist/index.vue'	
import {filterData2} from '@/static/js/filter.js'
export default{
	components:{comlist},
	data() {
		return {
			list: null,
			options: [{
				text: '删除',
				style: {
					backgroundColor: '#EE2437' ,// 删除按钮背景  红的
				}
			}],
			listtitle:'生活方式问卷',
			listLabel:[
				{
					name:'问卷编号：',
					key:'questionNumber'
				},
				{
					name:'填写时间：',
					key:'questionTime'
				},
			],
			showModal:false,
			showContent:'',
			page: 1,
			nullData:false,
			SearchuserId:'',
			deleteList:''
		}
	},
	onLoad() {
		if(uni.getStorageSync('load') == 1){
			uni.removeStorageSync('load')
			location.reload()
		}else{
			this.getlist({pageSize:10,pageIndex:this.page,userId:this.SearchuserId})
		}
	},
	onReachBottom(){
		if(this.nullData == true){
			return;
		}
		this.page = this.page + 1
		this.getlist({pageSize:10,pageIndex:this.page,userId:this.SearchuserId})
	},
	methods:{
		filterData2,
		comSearch(e) {
			const _this = this;
			_this.page = 1
			_this.SearchuserId = e == 'all'? '' : e.userId
			_this.nullData = false
			_this.$api.Questionnairelist({pageSize:10,pageIndex:1,userId:e.userId}).then(res=>{
				var data = res.data.result && res.data.result.list.map((a)=>{
					a.updateTime = _this.filterData2(a.updateTime)
					return a
				}) || []
				_this.list =  data
				if(_this.list.length >= (res.data.result && res.data.result.totalCount)){
					_this.nullData = true;
				}
			})
		},
		getlist(data){
			const _this = this;
			_this.$api.Questionnairelist(data).then(res=>{
				var data = res.data.result && res.data.result.map((a)=>{
					a.updateTime = _this.filterData2(a.updateTime)
					return a
				}) || []
				
				if(_this.deleteList == 1) {
					_this.list = []
					_this.list = data
					_this.deleteList = ''
				}else {
					_this.list = _this.list ? _this.list.concat(data) : data
				}
				if(_this.list.length >= (res.data.result && res.data.result.totalCount)){
					_this.nullData = true;
				}
			})
		},
		bindClick(e){
			console.log(e)
			this.showModal = true
			this.showContent = '确认删除此生活方式问卷'
			this.delItem = e
			// UserInfodelete
		},
		Modalconfirm(){
			this.$api.QuestionnaireDel(this.delItem.id).then((res)=>{
				if(res.data.returnCode == 200){
					uni.showToast({
						title:'删除成功',
						icon:'none'
					})
					this.deleteList = 1;
					this.page = 1;
					this.getlist({pageIndex:this.page,pageSize:10,userId:this.SearchuserId})
				}
			})
		},
		jump(item){
			!item.status || item.status == 1?
				uni.navigateTo({url:encodeURI('/pages/quickly/assessment/investigation?id='+item.id+'&userId='+item.userId+'&userName='+item.realName+'&questionNumber='+item.questionNumber)})
			:
				uni.navigateTo({url:'/pages/quickly/assessment/toView?id='+item.id+'&userId='+item.userId+'&userName='+item.realName+'&questionNumber='+item.questionNumber})
		}
	}
}
</script>

<style>
	
</style>
